package com.nuonuo.util.tmp;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.util.CollectionUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author duan
 * @version 1.0
 * @date 2024/2/26 10:29
 */
public class StreamNoneMatchTest {

    public static void main(String[] args) throws ParseException {
        DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date beginDate = dateFormat2.parse("2023-02-23 00:00:00");
        Date fitBeginTime = dateFormat1.parse("2023-02-23");
        Date fitEndTime = dateFormat1.parse("2023-02-23");
        Date createDate = dateFormat2.parse("2023-02-23 14:23:33");
        FpmpSyncInvoiceTask task1 = new FpmpSyncInvoiceTask(fitBeginTime, fitEndTime, createDate);
        List<FpmpSyncInvoiceTask> list1 = new ArrayList<>();
        System.out.println("empty = " + judgeNeedQs(beginDate, list1));
        list1.add(task1);
        System.out.println("one = " + judgeNeedQs(beginDate, list1));
    }

    private static boolean judgeNeedQs(Date beginDate, List<FpmpSyncInvoiceTask> hasTaskList) {
        if (CollectionUtils.isEmpty(hasTaskList)) {
            return true;
        }
        if (beginDate == null) {
            return true;
        }
        return hasTaskList.stream()
                .noneMatch(x -> x.getFitBeginTime() != null && x.getFitEndTime() != null
                        && beginDate.compareTo(x.getFitBeginTime()) >= 0
                        && beginDate.compareTo(x.getFitEndTime()) <= 0
                        && (x.getCreateTime().getTime() - beginDate.getTime() >= DateUtils.MILLIS_PER_DAY));
    }

    @Data
    public static class FpmpSyncInvoiceTask {

        public FpmpSyncInvoiceTask() {}

        public FpmpSyncInvoiceTask(Date fitBeginTime, Date fitEndTime, Date createTime) {
            this.fitBeginTime = fitBeginTime;
            this.fitEndTime = fitEndTime;
            this.createTime = createTime;
        }

        /**
         * 主键
         */
        private Long id;

        /**
         * 外键
         */
        private Long referId;

        /**
         * 税号
         */
        private String taxnum;

        /**
         * 企业名称
         */
        private String corpName;

        /**
         * 数电账号
         */
        private String account;

        /**
         * 任务序号
         */
        private String taskNo;

        /**
         * 成功失败原因描述
         */
        private String message;

        /**
         * 同步成功发票数量
         */
        private Integer syncNum;

        /**
         * 状态：-1-推送失败,0-推送成功,1-成功,2-失败
         */
        private Integer state;

        /**
         * 防重开成功的发票流水号
         */
        private String successInvoice;
        /**
         * 防重开成功的数量
         */
        private Integer successNum;

        /**
         * 操作人
         */
        private String operator;

        /**
         * 取票开始时间
         */
        @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
        private Date fitBeginTime;

        /**
         * 取票结束时间
         */
        @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
        private Date fitEndTime;

        /**
         * 创建时间
         */
        private Date createTime;

        /**
         * 更新时间
         */
        private Date updateTime;
    }
}


